package com.jwater.core.net;

import java.net.InetSocketAddress;

import com.jwater.core.common.IpPort;

import jwater.io.netty.channel.ChannelHandlerContext;
/**
 * @description:
 * @author: jnner
 * @createDate: 2021/2/5
 * @version: 1.0
 */
public class NettyUtils {
	public static String getId(ChannelHandlerContext ctx) {
		IpPort ipPort = getHost(ctx);
		String nodeId = ipPort.ip + ":" + ipPort.port;
		return nodeId;
	}

	public static IpPort getHost(ChannelHandlerContext ctx) {
		InetSocketAddress insocket = (InetSocketAddress) ctx.channel().remoteAddress();
		String ip = insocket.getAddress().getHostAddress();
		int port = insocket.getPort();
		return new IpPort(ip, port);
	}
}
